package com.yonyou.marketing.app.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.AppResponse;
import org.marketing.common.constants.ResultMsgConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.marketing.app.api.constant.AppConstant;
import com.yonyou.marketing.app.api.dto.NaireCommit;
import com.yonyou.marketing.app.api.service.AppQuestionnaireService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Administrator
 * @date 2017年6月30日
 */
@RestController
@RequestMapping(value = AppConstant.BASE_PATH + "/" + AppConstant.VERSION)
@Api("APP调查问券API")
public class AppQuestionnaireController {

	private Logger          logger = Logger.getLogger(AppQuestionnaireController.class);

	@Autowired
    private AppQuestionnaireService appQuestionnaireService;
	
	/**
     * 调查询问卷类型
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/questionType", method = RequestMethod.POST)
    @ApiOperation(value = "调查询问卷类型", notes = "调查询问卷类型")
    public AppResponse<List<Map<String, Object>>> questionType(
			@RequestParam(value = "queryType", required = true) Integer queryType,
            @RequestParam(value = "userId", required = true) String userId) {
        logger.info("AppQuestionnaireController.questionType==>start...");
        try {
        	List<Map<String, Object>> list = appQuestionnaireService.questionType(queryType, userId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, list, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppQuestionnaireController.questionType==>end...");
        }
    }
    /**
     * 查询介绍页面信息
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/explainView", method = RequestMethod.POST)
    @ApiOperation(value = "查询介绍页面信息", notes = "查询介绍页面信息")
    public AppResponse<Map<String, Object>> explainView(@RequestParam(value = "qneId", required = true) Integer qneId) {
        logger.info("AppQuestionnaireController.explainView==>start...");
        try {
        	Map<String, Object> map = appQuestionnaireService.explainView(qneId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppQuestionnaireController.explainView==>end...");
        }
    }
    /**
     * 查询问卷详情信息
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/questionNaireDetail", method = RequestMethod.POST)
    @ApiOperation(value = "查询问卷详情信息", notes = "查询问卷详情信息")
    public AppResponse<Map<String, Object>> questionNaireDetail(@RequestParam(value = "qneId", required = true) Integer qneId
    		,@RequestParam(value = "userId", required = true) String userId) {
        logger.info("AppQuestionnaireController.questionNaireDetail==>start...");
        try {
        	Map<String, Object> map = appQuestionnaireService.questionNaireDetail(qneId,userId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppQuestionnaireController.questionNaireDetail==>end...");
        }
    }
    /**
     * 已答问卷详情
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/questionResultDetail", method = RequestMethod.POST)
    @ApiOperation(value = "已答问卷详情", notes = "已答问卷详情")
    public AppResponse<Map<String, Object>> questionResultDetail(@RequestParam(value = "qneId", required = true) Integer qneId
    		,@RequestParam(value = "userId", required = true) String userId) {
        logger.info("AppQuestionnaireController.questionResultDetail==>start...");
        try {
        	Map<String, Object> map = appQuestionnaireService.questionResultDetail(qneId,userId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppQuestionnaireController.questionResultDetail==>end...");
        }
    }
    /**
     * 提交问卷信息
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/commitNaire", method = RequestMethod.POST)
    @ApiOperation(value = "提交问卷信息", notes = "提交问卷信息")
    public AppResponse<Map<String, Object>> commitNaire(@RequestParam("answer") String answer
    		,@RequestParam("qneId") String qneId
    		,@RequestParam("questionId") String questionId
    		,@RequestParam("sfdt") String sfdt
    		,@RequestParam("twoId") Integer twoId
    		,@RequestParam("userId") String userId) {
        logger.info("AppQuestionnaireController.commitNaire==>start...");
        try {
        	NaireCommit commit = new NaireCommit();
        	commit.setAnswer(answer);
        	commit.setQneId(qneId);
        	commit.setQuestionId(questionId);
        	commit.setSfdt(sfdt);
        	commit.setTwoId(twoId);
        	commit.setUserId(userId);
        	Map<String, Object> map = appQuestionnaireService.commitNaire(commit);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppQuestionnaireController.commitNaire==>end...");
        }
    }
}
